Skip to content

perf(workspace): shorten model-facing workspace IDs - #129

Merged
Waishnav merged 1 commit into
mainfrom
perf/short-workspace-ids
Aug 4, 2026
Merged

perf(workspace): shorten model-facing workspace IDs#129
Waishnav merged 1 commit into
mainfrom
perf/short-workspace-ids

Conversation

@Waishnav

@Waishnav Waishnav commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Workspace IDs are repeated across model-facing tool calls, and the current UUID-based values add unnecessary context overhead. New workspaces now use a compact ws_ prefix followed by 10 lowercase hex characters, while existing persisted IDs continue to work unchanged because IDs remain opaque strings.

Summary by CodeRabbit

  • Improvements
    • Workspace identifiers are now generated in a shorter, consistent format: ws_ followed by 10 lowercase hexadecimal characters.
    • Newly opened workspaces continue to receive unique identifiers in the updated format.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Workspace IDs now use 5 random bytes encoded as hexadecimal. The checkout test verifies the ws_ prefix and 10-character lowercase hexadecimal suffix.

Changes

Workspace ID generation

Layer / File(s) Summary
Generate and validate workspace IDs
src/workspaces.ts, src/workspaces.test.ts
The generator uses randomBytes(5) and hexadecimal encoding. The checkout test validates the resulting ws_ ID format.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Poem

A rabbit checks the workspace trail,
Ten hex hops without fail.
ws_ leads the way,
Bytes sparkle and play,
Tests guard each fresh detail.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the change to shorten workspace IDs used in model-facing tool calls.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/short-workspace-ids

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Waishnav
Waishnav merged commit 6f83396 into main Aug 4, 2026
4 of 5 checks passed
@greptile-apps

greptile-apps Bot commented Aug 4, 2026

Copy link
Copy Markdown

Greptile Summary

The PR shortens newly generated workspace IDs from UUIDs to a ws_ prefix followed by ten hexadecimal characters while retaining opaque-string compatibility for existing IDs.

  • Replaces UUID generation with five cryptographically random bytes.
  • Adds a test asserting the new compact workspace-ID format.

Confidence Score: 4/5

The PR appears safe to merge, though collision recovery would make the deliberately reduced identifier space more robust for long-lived installations.

The new format behaves as intended, but a duplicate 40-bit ID would currently fail persistence or overwrite an in-memory workspace rather than being regenerated.

Files Needing Attention: src/workspaces.ts

Important Files Changed

Filename Overview
src/workspaces.ts Changes workspace IDs to a 40-bit random format, but does not add collision detection or retry handling.
src/workspaces.test.ts Verifies that newly opened workspaces use the expected compact ID format.

Reviews (1): Last reviewed commit: "perf(workspace): shorten workspace ids" | Re-trigger Greptile

Comment thread src/workspaces.ts
}): Promise<WorkspaceContext> {
const workspace: Workspace = {
id: `ws_${randomUUID()}`,
id: `ws_${randomBytes(5).toString("hex")}`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Handle compact ID collisions

The new 40-bit ID space has no collision retry: a duplicate causes the persisted workspace insert to fail with a primary-key error, while registries without a store silently replace the existing workspace in the in-memory map.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/workspaces.ts`:
- Line 358: Update workspace creation around the ID generation in the workspace
factory to prevent collisions from overwriting existing entries or sessions. Use
a larger collision-safe ID namespace, or atomically check the generated ID
against this.workspaces and retry before inserting and returning the workspace;
preserve the existing workspace and session data when a collision occurs.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1d3d5664-d5dc-4013-aafa-43c81b0f4900

📥 Commits

Reviewing files that changed from the base of the PR and between 81a0093 and 0e3e14a.

📒 Files selected for processing (2)
  • src/workspaces.test.ts
  • src/workspaces.ts

Comment thread src/workspaces.ts
}): Promise<WorkspaceContext> {
const workspace: Workspace = {
id: `ws_${randomUUID()}`,
id: `ws_${randomBytes(5).toString("hex")}`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Narrow static proxy. It does not run packaged npm/npx installs or MCP hosts.
rg -n --glob '!node_modules/**' \
  -P '\b(createSession|getSession|getWorkspace|workspaceId|WorkspaceStore|randomUUID|randomBytes)\b' .

Repository: Waishnav/devspace

Length of output: 28095


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== src/workspace-store.ts outline =="
ast-grep outline src/workspace-store.ts --view expanded || true

echo "== src/workspace-store.ts relevant sections =="
sed -n '1,140p' src/workspace-store.ts
sed -n '180,225p' src/workspace-store.ts

echo "== src/workspaces.ts outline =="
ast-grep outline src/workspaces.ts --view expanded || true

echo "== src/workspaces.ts relevant sections =="
sed -n '1,120p' src/workspaces.ts
sed -n '230,390p' src/workspaces.ts

echo "== deterministic capacity/collision proxy =="
python3 - <<'PY'
from math import sqrt
import math
space = 2**40
# approximate birthday median / sqrt(2*N*ln(2)) when p=0.5
median = int(sqrt(2 * space * math.log(2))) + 1
print(f"id_space={space}")
print(f"estimated_approximate_sessions_for_50_percent_collision={median}")
print(f"hex_bytes_generated={5}")
print(f"expected_replacements_per_unique_workspace={space/(space-median)**2:.1e}" if False else "")
# Show tiny probabilities for small n via Poisson approximation n^2/(2 space).
for n in [1, 10, 1_000, 10_000]:
    n = int(n)
    p = n*(n-1)/(2*space)
    print(f"n={n}, expected_pairs={p:.2e}, p_collision_lower_bound_by_pairs={min(p,1):.6e}")
PY

Repository: Waishnav/devspace

Length of output: 19695


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== src/workspace-store.ts createSession full relevant block with line numbers =="
nl -ba src/workspace-store.ts | sed -n '66,88p'

echo "== database schema workspace session constraints =="
nl -ba src/db/schema.ts | sed -n '70,135p'

echo "== workspace ID consumers around collision handling =="
nl -ba src/workspaces.ts | sed -n '90,185p'
nl -ba src/server.test.ts | sed -n '60,180p' | sed -n '25,170p'

Repository: Waishnav/devspace

Length of output: 276


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== src/workspace-store.ts createSession full relevant block with line numbers =="
awk '{printf "%6d\t%s\n", NR, $0}' src/workspace-store.ts | sed -n '66,88p'

echo "== database schema workspace session constraints =="
awk '{printf "%6d\t%s\n", NR, $0}' src/db/schema.ts | sed -n '70,135p'

echo "== workspace ID consumers around collision handling =="
awk '{printf "%6d\t%s\n", NR, $0}' src/workspaces.ts | sed -n '90,185p'
awk '{printf "%6d\t%s\n", NR, $0}' src/server.test.ts | sed -n '60,180p'

Repository: Waishnav/devspace

Length of output: 13915


Make the 40-bit workspace ID space collision-safe.

randomBytes(5).toString("hex") creates only 2^40 possible IDs. A collision can replace an existing workspace in this.workspaces.set(workspace.id, workspace) and can also overwrite the existing workspace session with the new workspace root/data. Use a collision-safe ID namespace, or enforce uniqueness atomically with retry before returning the workspace. The current tests do not cover ID collisions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/workspaces.ts` at line 358, Update workspace creation around the ID
generation in the workspace factory to prevent collisions from overwriting
existing entries or sessions. Use a larger collision-safe ID namespace, or
atomically check the generated ID against this.workspaces and retry before
inserting and returning the workspace; preserve the existing workspace and
session data when a collision occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant